package com.shxy.rlzy.mapper;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.shxy.rlzy.entity.SalaryTask;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

/**
 * <p>
 *  Mapper 接口
 * </p>
 *
 * @author tanhao
 * @since 2022-03-19
 */
public interface SalaryTaskMapper extends BaseMapper<SalaryTask> {

    /**
     * 修改任务状态
     * @param taskId
     * @param statu
     */
    @Update("UPDATE emp_salary_task SET statu=#{statu} WHERE id=#{taskId}")
    int changeStatuById(long taskId, int statu);

    /**
     * 分页查询列表
     * @param start
     * @param size
     * @return
     */
    @Select("SELECT DISTINCT st.*," +
            "(SELECT COUNT(si.id) FROM emp_salary_item AS si WHERE si.task_id=st.id) AS total," +
            "(SELECT COUNT(si.id) FROM emp_salary_item AS si WHERE si.task_id=st.id AND si.statu=3) AS completed " +
            "FROM emp_salary_task AS st LEFT JOIN emp_salary_item AS si ON si.task_id=st.id LIMIT #{start},#{size}")
    List<SalaryTask> getPagedList(int start, int size);
}
